package cn.edu.nit.sys.timer;

import cn.edu.nit.sys.mapper.SubjectMapper;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @Author 罗文斌
 * @Date 2023/5/2
 * @Version 1.0.0
 */
@Component
public class UpdateSignDataTask implements Job {

    @Autowired
    private SubjectMapper subjectMapper;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        String signId = jobExecutionContext.getJobDetail().getJobDataMap().get("signId").toString();
        List<Map<String, String>> noSignList = subjectMapper.noSignList(signId);
        for(Map<String, String> map : noSignList) {
            String id = UUID.randomUUID().toString().replaceAll("\\-", "");
            String status = "1".equals(map.get("noSign")) ? "4" : "0";
            String remark = "1".equals(map.get("noSign")) ? "请假" : "未签到";
            subjectMapper.addSignLog(id, signId, map.get("uid"), "", "", status, remark);
        }
    }
}
